using System;

namespace UnitTesting.Fixturing
{
	class FactoryValueProvider<T> : IValueProvider
	{
		readonly Func<T> _factory;

		internal Func<T> Factory
		{
			get { return _factory; }
		}

		internal FactoryValueProvider(Func<T> factory)
		{
			_factory = Ensure.IsNotNull(() => factory);
		}

		public object Create(Type type)
		{
			Ensure.IsNotNull(() => type);
			return type != (typeof (T)) ? NotResolved.Value : _factory();
		}
	}
}